package com.lifeservice.console.service.impl;

import com.lifeservice.common.core.redis.RedisCache;
import com.lifeservice.common.utils.DateUtils;
import com.lifeservice.console.domain.LifeWorkClass;
import com.lifeservice.console.mapper.LifeWorkClassMapper;
import com.lifeservice.console.service.ILifeWorkClassService;
import com.lifeservice.util.LifeServiceConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 排班时间子Service业务层处理
 *
 * @author lifeservice
 * @date 2023-02-28
 */
@Service
public class LifeWorkClassServiceImpl implements ILifeWorkClassService {
    @Autowired
    private LifeWorkClassMapper lifeWorkClassMapper;

    @Autowired
    private RedisCache redisCache;

    /**
     * 查询排班时间子
     *
     * @param id 排班时间子主键
     * @return 排班时间子
     */
    @Override
    public LifeWorkClass selectLifeWorkClassById(String id) {
        LifeWorkClass lifeWorkClass = redisCache.getCacheObject(LifeServiceConstants.WORK_CLASS_ID_CACHE_PREFIX + id);
        if (null != lifeWorkClass) {
            return lifeWorkClass;
        }
        lifeWorkClass = lifeWorkClassMapper.selectLifeWorkClassById(id);
        redisCache.setCacheObject(LifeServiceConstants.WORK_CLASS_ID_CACHE_PREFIX + id, lifeWorkClass, 60, TimeUnit.MINUTES);
        return lifeWorkClass;
    }

    /**
     * 查询排班时间子列表
     *
     * @param lifeWorkClass 排班时间子
     * @return 排班时间子
     */
    @Override
    public List<LifeWorkClass> selectLifeWorkClassList(LifeWorkClass lifeWorkClass) {
        return lifeWorkClassMapper.selectLifeWorkClassList(lifeWorkClass);
    }

    /**
     * 新增排班时间子
     *
     * @param lifeWorkClass 排班时间子
     * @return 结果
     */
    @Override
    public int insertLifeWorkClass(LifeWorkClass lifeWorkClass) {
        lifeWorkClass.setCreateTime(DateUtils.getNowDate());
        return lifeWorkClassMapper.insertLifeWorkClass(lifeWorkClass);
    }

    /**
     * 修改排班时间子
     *
     * @param lifeWorkClass 排班时间子
     * @return 结果
     */
    @Override
    public int updateLifeWorkClass(LifeWorkClass lifeWorkClass) {
        lifeWorkClass.setUpdateTime(DateUtils.getNowDate());
        return lifeWorkClassMapper.updateLifeWorkClass(lifeWorkClass);
    }

    /**
     * 批量删除排班时间子
     *
     * @param ids 需要删除的排班时间子主键
     * @return 结果
     */
    @Override
    public int deleteLifeWorkClassByIds(String[] ids) {
        return lifeWorkClassMapper.deleteLifeWorkClassByIds(ids);
    }

    /**
     * 删除排班时间子信息
     *
     * @param id 排班时间子主键
     * @return 结果
     */
    @Override
    public int deleteLifeWorkClassById(String id) {
        return lifeWorkClassMapper.deleteLifeWorkClassById(id);
    }
}
